package com.gee.spring.cloud.aerospace.simulate.core.util;

import com.xy.spring.boot.redis.template.RedisTemplate;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

/**
 * @author gepengjun
 * @since 2024/7/4 14:23
 */
public class StaticRedisUtil implements InstantiationAwareBeanPostProcessor {

    private static RedisTemplate redisTemplate;

    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        if (bean instanceof RedisTemplate){
            StaticRedisUtil.redisTemplate = (RedisTemplate) bean;
        }
        return InstantiationAwareBeanPostProcessor.super.postProcessAfterInstantiation(bean, beanName);
    }

    public static long loopIncrease(String key, long min, long max){
        return redisTemplate.loopCount(key, min, max);
    }
}
